<template>
  <div class="mod-sp__spmatchitemteam">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item label="赛事" prop="province">
        <el-select style="width:150px" placeholder="请选择" v-model="dataForm.matchId">
          <el-option value="" label="全部">全部</el-option>
          <el-option
            v-for="item in matchList"
            :key="item.id"
            :label="item.matchName"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="赛项" prop="province">
        <el-select style="width:150px" placeholder="请选择" v-model="dataForm.matchItemId">
          <el-option value="" label="全部">全部</el-option>
          <el-option
            v-for="item in baseMatchList"
            :key="item.id"
            :label="item.itemName"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.phone" placeholder="代表队手机号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="submit()" type="primary">重新生成参赛编号</el-button>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.phone2" placeholder="选手手机号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="generateCertificatePic()" type="primary">重新生成参赛证件图</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="groupName" label="组别" header-align="center" align="center" width="180"></el-table-column>
      <el-table-column prop="userName" label="选手姓名" header-align="center" align="center" width="180"></el-table-column>
      <el-table-column prop="userPhone" label="选手手机号" header-align="center" align="center" width="230"></el-table-column>
      <el-table-column prop="ticket" label="选手编号" header-align="center" align="center" width="120"></el-table-column>
      <el-table-column prop="teamName" label="代表队名称" header-align="center" align="center" width="300"></el-table-column>
      <el-table-column prop="teamPhone" label="代表队手机号" header-align="center" align="center" width="120"></el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>


  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import baseService from "@/service/baseService";
export default defineComponent({
  setup() {
    const state = reactive({
      getDataListURL: "/sp/spticket/queryNoTicketUser",
      createdIsNeed: false,
      activatedIsNeed: false,
      getDataListIsPage: true,
      exportURL: "/sp/spmatchitemteam/export",
      deleteURL: "/sp/spmatchitemteam",
      deleteIsBatch: true,
      dataForm: {
        phone: "",
        phone2: "",
        matchId: "",
        matchItemId: "",
      },
      activeName: "first",
      detailVisible: false,
      detailId: "",
      matchList: [],
      baseMatchList: [],
    });
    return { ...useView(state), ...toRefs(state) };
  },
  created() {
    this.queryMatchList();
    this.queryMatchItemList();
  },
  methods: {
    // 赛事
    queryMatchList() {
      baseService.get("/sp/spmatch/list", {}).then((e: any) => {
        this.matchList = e.data;
      });
    },
    // 赛项
    queryMatchItemList() {
      baseService.post("/sp/spbasematchitem/list", {}).then((e: any) => {
        this.baseMatchList = e.data;
      });
    },
    submit() {
      baseService.get(`/sp/spticket/rebuild`, this.dataForm).then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.$message.success("操作成功");
      });
    },
    generateCertificatePic() {
      baseService.get(`/sp/spticket/generateCertificatePic`, this.dataForm).then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.$message.success("操作成功");
      });
    }
  }
});
</script>
